const mysql = require('mysql')
let db = {
  dbMysql (sql, arr, callback) {
    let db = mysql.createConnection({
      host: 'localhost',
      port: 3306,
      user: 'root',
      password: 'root',
      database: 'buy',
      //   timezone:
      dateStrings: true //解决时间格式
    })
    db.connect()
    db.query(sql, arr, callback)
    db.end()
  },
  // 中国标准时间 转换成 年月日
  formatDateTime (date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    var minute = date.getMinutes();
    minute = minute < 10 ? ('0' + minute) : minute;
    var second = date.getSeconds();
    second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
  }
}
module.exports = db